package short_semester.questionnaire_planet.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import short_semester.questionnaire_planet.pojo.MultiChoiceOption;
import short_semester.questionnaire_planet.pojo.MultiChoiceQuestion;

import javax.transaction.Transactional;
import java.util.List;

public interface MultiChoiceOptionDao extends JpaRepository<MultiChoiceOption,Integer> {
    public List<MultiChoiceOption> findByMultiChoiceQuestionOrderBySequenceAsc(MultiChoiceQuestion multiChoiceQuestion);
    
    @Transactional
    @Modifying
    public void deleteByMultiChoiceQuestion(MultiChoiceQuestion question);
    
    
    public List<MultiChoiceOption> findByMultiChoiceQuestion(MultiChoiceQuestion question);

    @Modifying
    @Transactional
    @Query("update MultiChoiceOption o set o.count=o.count+1 where o.id=:id")
    void submitOption(Integer id);

    @Modifying
    @Transactional
    @Query("update MultiChoiceOption o set o.store=o.store-1 where o.id=:id")
    void signOption(Integer id);
    
    List<MultiChoiceOption> findByMultiChoiceQuestionAndIdIn(MultiChoiceQuestion question,List<Integer> optionId);
}
